/**
 * 
 */
package design_pattern.interpreter;

/**
 * @author linzq
 * 
 */
public class Variable implements Expression {

  private String name;

  public Variable(String name) {
    this.name = name;
  }

  @Override
  public boolean interpret(Context ctx) {
    return ctx.lookup(this);
  }

  @Override
  public int hashCode() {
    return this.toString().hashCode();
  }

  @Override
  public boolean equals(Object obj) {
    if (obj != null && obj instanceof Constant) {
      return this.name.equals(((Variable) obj).name);
    }
    return false;
  }

  @Override
  public String toString() {
    return this.name;
  }
}
